package com.kunlun.basedata.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.kunlun.basedata.dao.INavigationDao;
import com.kunlun.basedata.model.NavigationModel;
import com.kunlun.basedata.model.vo.NavigationVo;
import com.kunlun.basedata.service.INavigateService;
import com.kunlun.common.utils.CommonUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class NavigateService implements INavigateService {

    private Logger log = LogManager.getLogger();

    @Autowired
    private INavigationDao navigationDao;

    @Override
    public List<NavigationVo> getAllNavigate(NavigationVo model) throws Exception {
        Map<String, Object> queryMap = CommonUtil.packageQueryMap(model, 0, 0);
        List<NavigationVo> navigationVos = navigationDao.getAllNavigate(queryMap);
        return navigationDao.getAllNavigate(queryMap);
    }

    @Override
    public void addNavigate(String data) throws Exception {
        List<NavigationModel> models = JSONArray.parseArray(data, NavigationModel.class);
        for (NavigationModel model : models) {
            model.setId(CommonUtil.generateUUID());
        }
        navigationDao.deleteNavigate();
        navigationDao.addNavigate(models);
    }

    @Override
    public void updateNavigate(NavigationModel model) throws Exception {
        navigationDao.updateNavigate(model);
    }
}
